package com.pj.wisdomlogistics.ui.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.entity.PlanCar;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

public class CarPlanSimpleAdapter extends BaseAdapter<PlanCar, BaseViewHolder> {
    public CarPlanSimpleAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.item_meeting_plan_date);
    }

    @Override
    public void bindCustomViewHolder(BaseViewHolder viewHolder, int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final PlanCar item = getItem(position);

        if(position == 0){
            viewHolder.getTextView(R.id.tvTopLine).setVisibility(View.INVISIBLE);
        }

        viewHolder.getTextView(R.id.tv_date).setText(item.getMeetingDate());
        LinearLayout mLayout = viewHolder.getView(R.id.ll_meeting_plan);
        for (int i = 0; i < item.getMeetingTimeAxis().size(); i++) {
            View mView = LayoutInflater.from(context).inflate(R.layout.item_meeting_plan_time , null);
            TextView mTvApplyTime = (TextView) mView.findViewById(R.id.tv_time);
            TextView mTvApplyDept = (TextView) mView.findViewById(R.id.tv_apply_dept);
            TextView mTvApplyPhone = (TextView) mView.findViewById(R.id.tv_apply_phone);
            mTvApplyTime.setText(item.getMeetingTimeAxis().get(i).getStartTime());
            mTvApplyDept.setText(item.getMeetingTimeAxis().get(i).getApplyDept());
            mTvApplyPhone.setText(item.getMeetingTimeAxis().get(i).getLinkmanTel());
            mLayout.addView(mView);

            final String tel = item.getMeetingTimeAxis().get(i).getLinkmanTel();

            mTvApplyPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClick.call(tel);
                }
            });
        }

    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public onItemClick mOnItemClick;

    public interface onItemClick{
        public void call(String tel);
    }

    public void setListener(onItemClick mListener){
        this.mOnItemClick = mListener;
    }

}
